﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Program
    {
        private volatile int val = 0;

        static void Main(string[] args)
        {
            var example = new Program();

            Task.Run(() => Interlocked.Increment(ref example.val));

            while (example.val == 0) ;
            // this never happens if val is not volatile
            Console.WriteLine("done.");
            Console.ReadLine();
        }
    }
}
